﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HROReporting.Model.Studenten;
using HROReporting.Infrastructure.UnitOfWork;
using NHibernate;
using NHibernate.Criterion;
using HROReporting.Infrastructure.Querying;

namespace HROReporting.Repository.NHibernate.Repositories
{
    public class StudentRepository : Repository<Student, int>, IStudentRepository
    {
        public StudentRepository(IUnitOfWork uow)
            : base(uow)
        {
        }

        public Student FindBy(string email)
        {
            ICriteria criteriaQuery = SessionFactory.GetCurrentSession()
                .CreateCriteria(typeof(Student))
                .Add(Expression.Eq(PropertyNameHelper
                .ResolvePropertyName<Student>
                (s => s.Email), email));

            IList<Student> students = criteriaQuery.List<Student>();

            Student student = students.FirstOrDefault();
            return student;
        }

        public Student GetStudentByAuthenticationToken(string authenticationToken)
        {
            ICriteria criteriaQuery = SessionFactory.GetCurrentSession()
                .CreateCriteria(typeof(Student))
                .Add(Expression.Eq(PropertyNameHelper
                .ResolvePropertyName<Student>
                (d => d.Email), authenticationToken));

            IList<Student> studenten = criteriaQuery.List<Student>();
            Student student = studenten.FirstOrDefault();

            return student;
        }

        public Reservering GetReserveringenByAuthenticationToken(string authenticationToken)
        {
            ICriteria criteriaQuery = SessionFactory.GetCurrentSession()
                .CreateCriteria(typeof(Reservering))
                .Add(Expression.Eq(PropertyNameHelper
                .ResolvePropertyName<Reservering>
                (t => t.User), authenticationToken));

            IList<Reservering> reserveringen = criteriaQuery.List<Reservering>();
            Reservering reservering = reserveringen.FirstOrDefault();

            return reservering;




            throw new NotImplementedException();
        }

    }
}
